package webservice.client;

import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;

public class CallWSMethods {

    private Service service;

    public boolean addProduit (Produit produit) {
        try {
            URL wsdlLocation = new URL("http://127.0.0.1:8080/ws/ServeurWS?WSDL");
            QName serviceQName = new QName("http://server.webservice/", "ServeurWSService");
            service = Service.create(wsdlLocation, serviceQName);

            ServeurWS myService = service.getPort(ServeurWS.class);
            return myService.addProduit(produit);

        } catch (Exception ex) {
            System.err.println(ex.getMessage());
            return false;
        }
    }

    public String getEnchereStatus (int idProduit) {
        try {
            URL wsdlLocation = new URL("http://127.0.0.1:8080/ws/ServeurWS?WSDL");
            QName serviceQName = new QName("http://server.webservice/", "ServeurWSService");
            service = Service.create(wsdlLocation, serviceQName);

            ServeurWS myService = service.getPort(ServeurWS.class);
            return myService.getEnchereStatus(idProduit);

        } catch (Exception ex) {
            return ex.getMessage();
        }
    }
}
